<?php
/**
@version 1.0: mod_ltc_weather
Author: Shape 5 - Professional Template Community
Free extension available for download at www.shape5.com
*/


// no direct access
defined('_JEXEC') or die('Restricted access');
global $mosConfig_offset, $mosConfig_live_site, $mainframe;
$text  = $params->get( 'textif');
$zipcodes  = $params->get( 'zipcodes');
$s5_tempscale  = $params->get( 's5_tempscale');
if ($zipcodes) {
    $zipcode = preg_split('/[\n,]|<br \/>/', $zipcodes);
	}else {
		$zipcode = "VMXX0006";
	}

$LiveSite = JURI::base();
?>
	
<?php
$br = strtolower($_SERVER['HTTP_USER_AGENT']); // what browser.
if(ereg("msie 6", $br)) {
$iss_ie6 = "yes";
} 
else {
$iss_ie6 = "no";
}
?>

<?php if ($s5_tempscale == "f") { }?>
		

<script type="text/javascript">//<![CDATA[
    document.write('<link href="<?php echo $LiveSite?>/modules/mod_ltc_weather/ltc_weather/style.css" rel="stylesheet" type="text/css" media="screen" />');
//]]></script>	

<?php
	
	error_reporting(0); 
	
	include('weather.class.php');
	$ltc_head="";
	$ltc_select="";
	$ltc_body="";
	$ltc_bottom="";
	
	if ($iss_ie6 == "yes") {
			$ltc_head.="<div><div><div class=\"ltc_weather_middle\"><div class=\"ltc_weather_tl\"></div><div class=\"ltc_weather_tr\"></div></div><div	 style=\"clear:both;margin-top:-6px;\"></div>";
			} else {
			$ltc_head.= "<div><div><div class=\"ltc_weather_middle\"><div class=\"ltc_weather_tl\"></div><div class=\"ltc_weather_tr\"></div></div><div style=\"clear:both;\"></div>";		
			}	
			
			$ltc_head.= "<div class=\"ltc_weather_brep\"><div class=\"ltc_weather_rl\"><div class=\"ltc_weather_rr\">";
			$ltc_select.="<div align=\"center\"><select style=\"border-top:0px; border-left:0px;  border-bottom: solid 1px #2982D6;  font-family:Cambria; font-weight:bolder; text-transform:uppercase; width:90%\" onchange=\"ShowCity(this.value);\">";
			
			
	
	
	for ($i = 0; $i < count($zipcode); $i ++)
	{

		if ($s5_tempscale == "f") {
		
		$ret = weather($zipcode[$i],  ($_GET['u'] == 'f'));
		}

		if ($s5_tempscale == "c") {
		
		$ret = weather($zipcode[$i],  ($_GET['u'] = 'c'));
		}
			
				
			
			foreach($ret as $day) {
			if(isset($day['temp'])) {	
			
			switch ($day['text']) {
				case "Mostly Cloudy":
					$day['text'] = "Trời nhiều mây";
					break;
				case "Mist":
					$day['text'] = "Trời có sương mù";
					break;
				case "Fair":
					$day['text'] = "Trời đẹp";
					break;
				case "Thunderstorm":
					$day['text'] = "Đang có sấm sét";
					break;
				case "Thunder":
					$day['text'] = "Trời có sấm";
					break;
				case "Sunny":
					$day['text'] = "Trời đang nắng";
					break;
				case "Clear":
					$day['text'] = "Trời quang đãng";
					break;
				case "Partly Cloudy":
					$day['text'] = "Mây thay đổi";
					break;		
				case "Fog":
					$day['text'] = "Đang có sương mù";
					break;					
				case "Light Rain":
					$day['text'] = "Mưa nhỏ vài nơi";
					break;					
				case "Cloudy":
					$day['text'] = "Trời đang có mây";
					break;	
				case "Rain":
					$day['text'] = "Trời mưa";
					break;						
			}			
			$ltc_select.= "<option style=\"border-bottom:solid 1px #2982D6;\" value=\"ltc_weather_id".$i."\">".$ret[0]['location']."</option>";				
				$ltc_body.= "<div class=\"ltc_weather_padding\" id=\"ltc_weather_id".$i."\" style=\"display:none\"><div style=\"float:left;width:100%; background:url(". $LiveSite. '/modules/mod_ltc_weather/ltc_weather/'.$day['image'].') top right no-repeat;\"><strong><font color=#2982D6> '.$day['text'].'</font></strong><div style="float:left;font-size:11px;">';
			
				$ltc_body.= 'Nhiệt độ TB: '.$day['temp'].'<br/>';
				$ltc_body.= 'Gió '.$day['wind'].'<br/>';
				$ltc_body.= 'Độ ẩm: '.$day['humidity'].'<br/>';
				//$ltc_body.= 'Visibility: '.$day['visibility'].'<br/>';
				//$ltc_body.= 'pressure: '.$day['pressure'].'<br/>';
				$ltc_body.= 'Mặt trời lên: '.$day['sunrise'].'<br/>';
				$ltc_body.= 'Mặt trời lặn: '.$day['sunset'];		
				$ltc_body.= "</div></div><div style=\"clear: both;\"></div></div>";
				
				}
		}	
				
				
		
	}
	$ltc_select.= "</select></div>";
	$ltc_bottom.= "</div></div></div></div>";				
	$ltc_bottom.= "<div style=\"clear:both;\"><div class=\"ltc_weather_bmiddle\"><div class=\"ltc_weather_bl\"></div><div class=\"ltc_weather_br\"></div></div></div></div>";
	echo $ltc_head.$ltc_select;
	echo $ltc_body;
	echo $ltc_bottom;
	
	echo "<script language=\"javascript\" type=\"text/javascript\">\n";
	echo "document.getElementById('ltc_weather_id0').style.display='block';\n";
	echo "function ShowCity(z)\n";
	echo "{\n";
	for ($i = 0; $i < count($zipcode); $i ++)
	{
		echo "document.getElementById('ltc_weather_id".$i."').style.display='none';\n";
	}
	echo "document.getElementById(z).style.display='block';\n";
	echo "}\n";
	
	echo "</script>\n";
?>


